package org.jetlinks.community.mstn.entity.vo;

import lombok.Getter;
import org.jetlinks.community.device.entity.DeviceProperty;

import java.util.List;

@Getter
public class ProductAggResVO {
    private String name;
    public static ProductAggResVO of(List<ProductAggReqVO> aggList, DeviceProperty property) {
        ProductAggResVO vo = new ProductAggResVO();

        if (property.getValue() instanceof Number) {
            for (int i = 0; i < aggList.size(); i ++) {
                ProductAggReqVO agg = aggList.get(i);
                double value = ((Number) property.getValue()).doubleValue();
                if (value >= agg.getMin() && value < agg.getMax()) {
                    vo.name = agg.getName();
                    break;
                }
            }
        } else {
            vo.name = "异常数据";
        }
        return vo;
    }
}
